// 动画执行函数
const myRaf = function getRequestAnimationFrame() {
  if (window.requestAnimationFrame) {
    return requestAnimationFrame;
  }

  return (func) => {
    setTimeout(func, 0);
  };
}()

/**
 * 回到顶部
 *
 * @param {element} [scrollElement=null]
 * @param {number} [step=500]
 */
 function goTop(scrollElement = null, step = 500) {
  let scrollEl = scrollElement;

  if (scrollEl === null) {
    scrollEl = document.documentElement || document.body;
  }

  function scrollSlow() {
    const top = scrollEl.scrollTop;
    if (top > 0) {
      scrollEl.scrollTop = top - step;
      myRaf(scrollSlow);
    }
  }

  scrollSlow();
}

